package spark.graphics.scenegraph;

import java.util.LinkedList;

public abstract class SceneGraphNode {
	private LinkedList<SceneGraphNode> children;

	public SceneGraphNode addChild(SceneGraphNode child) {
		getChildren().add(child);
		return child;
	}

	protected LinkedList<SceneGraphNode> getChildren() {
		if(children == null) {
			children = new LinkedList<SceneGraphNode>();
		}
		return children;
	}

	protected void prepare() {
	}

	protected void cleanup() {
	}

	void render() {
		prepare();
		for(SceneGraphNode child : getChildren()) {
			child.render();
		}
		cleanup();
		clear();
	}

	private void clear() {
		if(children != null) {
			children.clear();
		}
	}
}